﻿@{ Layout = "~/Views/Shared/_Index.cshtml"; }
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/zTree/v3/css/metroStyle/metroStyle.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/zTree/v3/js/ztree.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/jquery.layout/1.4.4/jquery.layout-latest.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/jquery.layout/1.4.4/jquery.layout-latest.min.js"))
}
<div class="container-div">
    <div class="row">
       
        <div id="searchDiv" class="col-sm-12 search-collapse" style="display:none">
            <div class="select-list">
                <ul>
                    <li>
                        姓名/手机号码：<input id="key" col="Key" type="text" />
                    </li>
                    <li>
                        <div id="departmentId" col="DepartmentId"></div> <input type="hidden" id="prescriptionId" col="PrescriptionId" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="toolbar" class="btn-group-sm">
            <a id="btnAdd" class="btn btn-success" onclick="addEvent()"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var id = ys.request("prescriptionId");
    $("#prescriptionId").val(id);
    $(function ()
    {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/EyeFollowUp/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            sortName: 'BaseModifyTime',
            sortOrder: 'Asc',
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'RealName', title: '姓名', width: "8%", sortable: true },
                { field: 'FollowUpSort', title: '治疗次数', width: "8%", sortable: true },
                { field: 'GenderText', title: '性别', width: "5%", sortable: false },
                { field: 'Age', title: '年龄', width: "5%", sortable: false },
                {
                    field: 'ThisDate', title: '随访时间', width: "10%", sortable: true, formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd");
                    }},
                {
                    field: 'NextFollowUpTime', title: '下次随访时间', width: "10%", sortable: true, formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd");
                    } },
                { field: 'EyeLeftBefore', title: '左眼调理前', width: "10%", sortable: true },
                { field: 'EyeLeftAfter', title: '左眼调理后', width: "10%", sortable: true },
                { field: 'EyeLeftDayGrowthRate', title: '左眼当日增幅', width: "10%", sortable: true },
                { field: 'EyeLeftAllGrowthRate', title: '左眼总增幅', width: "10%", sortable: true },
                { field: 'EyeRightBefore', title: '右眼调理前', width: "10%", sortable: true },
                { field: 'EyeRightAfter', title: '右眼调理后', width: "10%", sortable: true },
                { field: 'EyeRightDayGrowthRate', title: '右眼当日增幅', width: "10%", sortable: true },
                { field: 'EyeRightAllGrowthRate', title: '右眼总增幅', width: "10%", sortable: true },

                {
                    field: 'BaseModifyTime', title: '创建时间', sortable: true, formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                //console.log(pagination)
                var queryString = $("#searchDiv").getWebControls(pagination);
                console.log(queryString)
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $("#gridTable").bootstrapTable("getSelections");
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? "编辑随访" : "添加随访",
            content: '@Url.Content("~/EyeFollowUp/EyeFollowUpForm")' + '?id=' + id,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                
                iframeWin.saveForm(index);
            }
        });
    }

   function addEvent() {
      
         ys.openDialog({
            title:  "添加随访",
             width: "100%",
             height: "100%",
             content: '@Url.Content("~/EyeFollowUp/EyeFollowUpForm")' + '?prescriptionId=' + id,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }


    function deleteForm() {
        var selectedRow = $("#gridTable").bootstrapTable("getSelections");
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm("确认要删除选中的" + selectedRow.length + "条数据吗？", function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/person/DeleteFormJson")' + '?ids=' + ids,
                    type: "post",
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>